import pandas as pd

# INSERT INTO midea_lims_new.actualtestvaluetableconfig
# (oid, createTime, editTime, equipmentName, equipmentACode, tableName, inUse, buId)
# VALUES(4052267522918, '2024-04-23 08:46:47', '2024-04-23 08:46:47', 'RV5000N.m恒载测试台1#', 'A2248000007220011', 'com.midea.ext.model.testmonitor.ActualTestValueJ', 1, NULL);



# 读取Excel文件
file_path = 'D:\\Users\\ex_yejing1\\Desktop\\时序数据库\\生活电器.xlsx'  # 替换为你的Excel文件路径
oid = 8158438470810
createTime = '2025-01-07 11:27:44'
editTime = '2025-01-07 11:28:10'
tableName = 'ActValYsj'

try:
    df = pd.read_excel(file_path)

    # 初始化一个空列表来存储元组
    data_list = []

    # 遍历DataFrame中的每一行
    for index, row in df.iterrows():
        try:
            # 提取第1、2、3、5列的数据（注意：列索引从0开始）
            row_values = (row[0], row[1], row[2], row[4])
            
            # 将元组添加到列表中
            data_list.append(row_values)

            index = 1

            # 打印结果
            for data_tuple in data_list:
                # print(data_tuple)
                tableName = data_tuple[3]
                # 判断 data_tuple[2]如果是1.0就返回1，如果是0.0，就返回0
                inUse = 1 if data_tuple[2] == 1.0 else 0
                print(f"INSERT INTO actualtestvaluetableconfig (oid, createTime, editTime, equipmentName, equipmentACode, tableName, inUse, buId) VALUES({oid}, '{createTime}', '{editTime}', '{data_tuple[0]}', '{data_tuple[1]}', '{tableName}', '{inUse}', NULL);")
                index += 1
                oid += 1

        except IndexError:
            print(f"行 {index} 缺少必要的列数据")
        except Exception as e:
            print(f"处理行 {index} 时发生错误: {e}")
   
except FileNotFoundError:
    print(f"文件 {file_path} 未找到")
except Exception as e:
    print(f"读取文件时发生错误: {e}")
    df = pd.DataFrame()  # 创建一个空的DataFrame以避免后续错误


